<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/1
 * Time: 22:03
 */

namespace Lib\Api;


class OrganizationBankApi extends UtilsApi {
    private static $modelName = 'OrganizationBank';

    /** 获取机构列表
     * @param $where
     * @param int $page_num
     * @param int $page_size
     * @param string $field
     * @return mixed
     */
    public static function getList($where, $page_num = 15, $page_size = 1, $field = "*") {
        $list = parent::getList(OrganizationBankApi::$modelName, $where, $page_num, $page_size, $field);
        return $list;
    }

    /** 获取机构列表
     * @param $where
     * @param string $field
     * @return mixed
     */
    public static function getListAll($where, $field = "*") {
        $model = M(OrganizationBankApi::$modelName);
        $list =  $model->field($field)->where($where)->select();//page两个参数（页码，条数），不需要自己计算
        return $list;
    }

    /** 获取所有子节点机构
     * @param $where
     * @param $left
     * @param string $field
     * @return mixed
     */
    public static function getAllByCondition($where, $left="", $field = "*") {
        $model = M();
        $list = $model->table('fs_organization_bank a')
            ->join($left)
            ->field($field)
            ->where($where)
            ->select();
        return $list;
    }

    /** 获取机构总数
     * @param $where
     * @return mixed
     */
    public static function getTotal($where) {
        $total = parent::getTotal(OrganizationBankApi::$modelName, $where);
        return $total;
    }

    /** 获取机构信息
     * @param $where
     * @param $left
     * @param $field
     * @return mixed
     */
    public static function getInfo($where, $left="", $field= "*") {
        $model = M();
        $customer = $model->table('fs_organization_bank a')
            ->join($left)
            ->field($field)
            ->where($where)
            ->find();

        return $customer;
    }

    /** 添加机构
     * @param $data
     * @return mixed
     */
    public static function add($data) {
        $id = parent::add(OrganizationBankApi::$modelName, $data);
        return $id;
    }

    /** 修改机构
     * @param $data
     * @return bool
     */
    public static function save($data) {
        $state = parent::save(OrganizationBankApi::$modelName, $data);
        return $state;
    }

    /** 删除机构
     * @param $where
     */
    public static function delete($where) {
        parent::delete(OrganizationBankApi::$modelName, $where);
    }
}